<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>get请求</h1>
    <form id="form" action="">
        <input id="ipt" type="text">
        <button id="btn">请输入学生Id</button>
    </form>
    <script>
        const oBtn = document.getElementById('btn')
        const oIpt = document.getElementById('ipt')
        const oForm = document.getElementById('form')
        // 提交from表单事件
        oForm.onsubmit=()=>{
            const userId = oIpt.value;
            //1. 创建实例化XMLHttpReuset
            const xhr= new XMLHttpRequest();
          
            // 2.打开路径
            // 参数1:请求方式 参数2:请求地址  参数3:是否异步
            xhr.open('get',`/user?userId=${userId}&_=${Date.now()}`,true)
            // 3.发送请求
            xhr.send();
            // 4.监听事件
            xhr.onreadystatechange=function(){
                if(xhr.readyState===4 && (xhr.status>=200 && xhr.status<300)){
                    console.log(xhr.responseText);
                }
            }
            return false;
        }
    </script>
</body>
</html>